package com.younion.dao;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.younion.common.base.BaseDAO;
import com.younion.common.base.BaseVO;
import com.younion.common.exception.BaseException;
import com.younion.common.paginator.Paginator;
import com.younion.vo.WebFileVO;

public class WebFileDAO extends BaseDAO {
	
	protected static final Log logger = LogFactory.getLog(WebFileDAO.class);
	
	public WebFileVO selectWebFileById(int id) throws BaseException {
		try {
			return (WebFileVO) this.getSqlMapClientTemplate().queryForObject("t_web_file.selectById", id);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(this.getClass().getSimpleName() +" method error");
		}
	}
	
	public boolean updateWebFileByMap(Map paramMap) throws BaseException {
        try{
        	this.update("t_web_file.updateByMap", paramMap);
        	return true;
        } catch(Exception e) {
        	logger.error(e.getMessage(), e);
        	throw new BaseException(this.getClass().getSimpleName() +" method error");
        }
    }
	
	public boolean deleteWebFileById(int id) throws BaseException {
        try{
        	this.getSqlMapClientTemplate().delete("t_web_file.deleteById", id);
        	return true;
        } catch(Exception e) {
        	logger.error(e.getMessage(), e);
        	throw new BaseException(this.getClass().getSimpleName() +" method error");
        }
    }
	
	public boolean deleteWebFileByIds(List list) throws BaseException {
        try{
        	this.getSqlMapClientTemplate().delete("t_web_file.deleteByIds", list);
        	return true;
        } catch(Exception e) {
        	logger.error(e.getMessage(), e);
        	throw new BaseException(this.getClass().getSimpleName() +" method error");
        }    
    }    
	
	 
	public int selectCountByMap(Map paramMap) throws BaseException {
		if (paramMap == null)
			return 0;
		try {
			return queryCount("t_web_file.selectByMapCount", paramMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(this.getClass().getSimpleName() +" method error");
		}
	}

	 
	public List selectForPage(Map condition, Paginator paginator) throws BaseException {
		if (condition == null)
			return null;
		int pageIndex = paginator.getStartIndex();
		int perPageSize = paginator.getPageSize();
		String sqlStr = "";
		try {
			Map vo = (Map) condition.get("paramMap");
			if (vo == null) {
				sqlStr = "t_web_file.selectAll";
			} else {
				sqlStr = "t_web_file.selectByMap";
			}
			return queryForPage(sqlStr, vo, pageIndex, perPageSize);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(this.getClass().getSimpleName() +" method error");
		}
	}

	 
	public Integer insertByVo(WebFileVO webFileVO) throws BaseException {
		if (webFileVO == null)
			return null;
		try {
			return (Integer) this.getSqlMapClientTemplate().insert("t_web_file.insertByVo", (BaseVO) webFileVO);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(this.getClass().getSimpleName() +" method error");
		}
	}
	
	public void updateTopById(Map map) throws BaseException {
		try {
			this.getSqlMapClientTemplate().update("t_web_file.updateTopById", map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(this.getClass().getSimpleName() +" method error");
		}
	}
	
	public int selectMaxTop() throws BaseException {
		try {
			Object obj = this.getSqlMapClientTemplate().queryForObject("t_web_file.selectMaxTop");
			if (obj == null) return 0;
			return ((Integer)obj).intValue();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(this.getClass().getSimpleName() +" method error");
		}
	}
	
	public List<WebFileVO> selectByIds(List list) throws BaseException {
		try {
			return this.getSqlMapClientTemplate().queryForList("t_web_file.selectByIds", list);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new BaseException(this.getClass().getSimpleName() +" method error");
		}
	}

}
